package com.itsm.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itsm.entity.Process;
import com.itsm.service.mapper.ProcessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@DS("master")
@Service
public class ProcessEngineerService {
    @Autowired
    private ProcessMapper processMapper;


    /**
     * 处理人数据信息查询
     * @param name
     * @return
     */
    public List<Process> selectListRespa(String name, Integer state,Integer is){
        QueryWrapper<Process> wrapper = new QueryWrapper();
        Map<String, Object> queryParamsMap = new HashMap<>();
        queryParamsMap.put("respa_name", name);
        queryParamsMap.put("state", state);
        queryParamsMap.put("is_accepted", is);
        queryParamsMap.put("is_delete", 1);
        wrapper.allEq(queryParamsMap).orderByDesc("process_no");
        return processMapper.selectList(wrapper);
    }


    public List<Process> selectListRespaRate(String name, Integer state,Integer is){
        QueryWrapper<Process> wrapper = new QueryWrapper();
        Map<String, Object> queryParamsMap = new HashMap<>();
        queryParamsMap.put("respa_name", name);
        queryParamsMap.put("state", state);
        queryParamsMap.put("is_accepted", is);
        queryParamsMap.put("is_delete", 1);
        wrapper.allEq(queryParamsMap).orderByDesc("process_no");
        wrapper.lambda().isNull(Process::getScore);
        return processMapper.selectList(wrapper);
    }


    public List<Process> selectListRespaRate1(String name, Integer state,Integer is){
        QueryWrapper<Process> wrapper = new QueryWrapper();
        Map<String, Object> queryParamsMap = new HashMap<>();
        queryParamsMap.put("respa_name", name);
        queryParamsMap.put("state", state);
        queryParamsMap.put("is_accepted", is);
        queryParamsMap.put("is_delete", 1);
        wrapper.allEq(queryParamsMap).orderByDesc("process_no");
        wrapper.lambda().isNotNull(Process::getScore);
        return processMapper.selectList(wrapper);
    }

    /**
     * 按照负责人查询全部工单
     * @param name 负责人姓名
     * @return 工单信息
     */
    public List<Process> selectAll(String name,String userName){
        if(userName == null || userName.isEmpty()){
            QueryWrapper<Process> wrapper = new QueryWrapper();
            Map<String, Object> queryParamsMap = new HashMap<>();
            queryParamsMap.put("respa_name", name);
            queryParamsMap.put("is_delete", 1);
            wrapper.allEq(queryParamsMap).orderByDesc("process_no");
            return processMapper.selectList(wrapper);
        }
        QueryWrapper<Process> wrapper = new QueryWrapper();
        Map<String, Object> queryParamsMap = new HashMap<>();
        queryParamsMap.put("respa_name", name);
        queryParamsMap.put("is_delete", 1);
        wrapper.allEq(queryParamsMap).orderByDesc("process_no");
        wrapper.allEq(queryParamsMap).like("create_name",userName).or().like("subject",userName).or().like("content",userName).orderByDesc("process_no");
        return processMapper.selectList(wrapper);

    }

    public List<Process> selectRateNo(String name,Integer state,Integer is){
        QueryWrapper<Process> wrapper = new QueryWrapper();
        Map<String, Object> queryParamsMap = new HashMap<>();
        queryParamsMap.put("respa_name", name);
        queryParamsMap.put("state", state);
        queryParamsMap.put("is_accepted", is);
        queryParamsMap.put("is_delete", 1);
        queryParamsMap.put("score", "");
        wrapper.allEq(queryParamsMap).orderByDesc("process_no");
        return processMapper.selectList(wrapper);
    }

    public List<Process> selectRate(String name,Integer state,Integer is){
        QueryWrapper<Process> wrapper = new QueryWrapper<>();
        Map<String, Object> queryParamsMap = new HashMap<>();
        queryParamsMap.put("respa_name", name);
        queryParamsMap.put("state", state);
        queryParamsMap.put("is_accepted", is);
        queryParamsMap.put("is_delete", 1);
        wrapper.allEq(queryParamsMap).ne("score", "").orderByDesc("process_no");
//        wrapper.lambda().isNotNull(Process::getScore);
        return processMapper.selectList(wrapper);
    }


}
